package com.rigsofrods.truckeditor.rig;

import java.util.Formatter;
import java.util.Locale;

/**Set nodes defaults
 * <a href="http://www.rigsofrods.com/wiki/pages/Truck_Description_File#Set_node_defaults">ror wiki</a>
 */
public final class NodeDefaults extends TruckTreeNode{		
	public double loadweight = 0;
	public double traction = 1.0;
	public double buoyancy = 1.0;
	public double surface = 1.0;
	private String options = "";
	
	private static final double LOADWEIGHT = 0;
	private static final double TRACTION = 1.0;
	private static final double BUOYANCY = 1.0;
	private static final double SURFACE = 1.0;
	private static final String OPTIONS = "";
	
	public NodeDefaults(){}
			
	public NodeDefaults(double loadweight, double traction,
			double buoyancy, double surface, String options) {
		set(loadweight, traction, buoyancy, surface, options);
	}
	
	public void set(
			double loadweight,
			double traction, 
			double buoyancy, 
			double surface, 
			String options){
		//negative value means reset to original 
		this.loadweight = (loadweight <= 0) ? LOADWEIGHT : loadweight;
		this.traction = (traction <= 0) ? TRACTION : traction;
		this.buoyancy = (buoyancy <= 0) ? BUOYANCY : buoyancy;
		this.surface = (surface <= 0) ? SURFACE : surface;
		this.options = (options == null) ? OPTIONS : options;
	}

	@Override
	public String getText() {
		return toString();
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		Formatter f = new Formatter(sb, Locale.US);
		f.format("%1.3f, %1.4f, %1.4f, %1.4f, %s", loadweight, traction,
				buoyancy, surface, options);
		f.close();
		return sb.toString();
	}

	@Override
	public SectionType getSectionType() {
		return SectionType.SINGLE_LINE_COMMAND;
	}
}